﻿DROP TRIGGER IF EXISTS  `pk_brand_log`; 
CREATE  TRIGGER `pk_brand_log` AFTER INSERT ON `open_brand`
  FOR EACH ROW BEGIN
DECLARE pkf varchar(50) DEFAULT "";
SELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="brand";
if pkf <> "brand" then
   INSERT INTO open_pk_log SET pk_from = 'brand', pk_id = NEW.brand_id;
ELSE
    update open_pk_log SET pk_id = NEW.brand_id WHERE pk_from = 'brand';
end if;
END;